/**
 * @param {string[]} queries
 * @param {string[]} words
 * @return {number[]}
 */
var numSmallerByFrequency = function (queries, words) {
  function check(s) {
    let res = 0, ch = 'z'
    for (let i = 0; i < s.length; i++) {
      if (s[i] < ch) {
        ch = s[i]
        res = 1
      } else if (s[i] == ch) res++
    }

    return res
  }


  let res = []
  for (let i = 0; i < words.length; i++) {
    words[i] = check(words[i])
  }

  words.sort((a, b) => a - b)
  for (let i = 0; i < queries.length; i++) {
    let count = check(queries[i])
    queries[i]=0
    for(let j=0;j<words.length;j++){
      if(words[j]>count){
        queries[i]=words.length-j
        break
      }
    }
  }

  return queries
};